Title
title: Coupled van der Pol oscillators
description:
date: 2020-04-30
tags:
- math
layout: layouts/post.njk
Coupled van der Pol oscillators https://scholarsarchive.library.albany.edu/cgi/viewcontent.cgi?article=1004&context=honorscollege_physics
$ g' = A sin ωt − γg − ω^2_0 z$
$z' = g$
from models.coupled.vanderpol import *
hv.notebook_extension()
van=get_plot()
van[0]
van
import numpy as np
from holoviews import HoloMap, VectorField
%load_ext holoviews.ipython
%output filename="Image-Pattern-Gaussian" holomap="gif"
holomap = HoloMap()
steps = np.linspace(-2.5, 2.5, 41)
x,y = np.meshgrid(steps, steps)
sine_rings = np.sin(x**2+y**2)*np.pi+np.pi
exp_falloff = 1/np.exp((x**2+y**2)/15)
for deg in np.linspace(0, 360, 128, endpoint=False):
vector_data = np.array([x.flatten()/5., y.flatten()/5.,
np.sin(deg*2*np.pi/360)*sine_rings.flatten(),
exp_falloff.flatten()]).T
holomap[deg] = VectorField(vector_data, group='Sine Ring')
holomap
import panel as pn
pn.extension('vega')
#This example demonstrates how to link Panel widgets to a Vega pane by editing the Vega spec using callbacks and triggering updates in the plot.
imdb = {
"$schema": "https://vega.github.io/schema/vega-lite/v3.json",
"data": {"url": "https://raw.githubusercontent.com/vega/vega/master/docs/data/movies.json"},
"transform": [{
"filter": {"and": [
{"field": "IMDB_Rating", "valid": True},
{"field": "Rotten_Tomatoes_Rating", "valid": True}
]}
}],
"mark": "rect",
"width": 600,
"height": 400,
"encoding": {
"x": {
"bin": {"maxbins":60},
"field": "IMDB_Rating",
"type": "quantitative"
},
"y": {
"bin": {"maxbins": 40},
"field": "Rotten_Tomatoes_Rating",
"type": "quantitative"
},
"color": {
"aggregate": "count",
"type": "quantitative"
}
},
"config": {
"view": {
"stroke": "transparent"
}
}
}
vega = pn.pane.Vega(imdb, width=750, height=425)
# Declare range slider to adjust the color limits
color_lims = pn.widgets.RangeSlider(name='Color limits', start=0, end=125, value=(0, 40), step=1)
color_lims.jslink(vega, code={'value': """
target.data.encoding.color.scale = {domain: source.value};
target.properties.data.change.emit()
"""})
# Declare slider to control the number of bins along the x-axis
imdb_bins = pn.widgets.IntSlider(name='IMDB Ratings Bins', start=0, end=125, value=60, step=25)
imdb_bins.jslink(vega, code={'value': """
target.data.encoding.x.bin.maxbins = source.value;
target.properties.data.change.emit()
"""})
# Declare slider to control the number of bins along the y-axis
tomato_bins = pn.widgets.IntSlider(name='Rotten Tomato Ratings Bins', start=0, end=125, value=40, step=25)
tomato_bins.jslink(vega, code={'value': """
target.data.encoding.y.bin.maxbins = source.value;
target.properties.data.change.emit()
"""})
pn.Row(vega, pn.Column(color_lims, imdb_bins, tomato_bins))
#import holoviews as hv
#hv.renderer('matplotlib').save(van[0], 'test', fmt='gif')
#%output filename="tmp" holomap='gif'
#van[0]
ω0 = 2500
ν = 100
µ = 10
ω2 = 300*25#554.365
A2=0
def deriv (y,t,A1,ω1):
sine1=A1*np.sin(ω1 * t)
sine2=A1*np.sin(ω2 *t)
zprime = y[1]
gprime = -ν *y[1]*(y[0]**2 - µ) - (ω0**2) * y[0] + sine1 + sine2
return np.array([ zprime , gprime, sine1 ])
plt.figure()
y = odeint(deriv, [0.1,0.1,0.], np.linspace(0, 1., 600000),args=(5e6, 2200)) # with w0=2500, get resonance or beating
plot_and_play(y)
plt.figure()
y = odeint(deriv, [0.1,0.1,0.], np.linspace(0, 1., 600000),args=(5e6, 2200)) # with w0=2500, get resonance or beating
plot_and_play(y)
import os
name='vanderpol_coupled_standalone'
path='~/mmy/jup/models/'
os.system(f'jupyter nbconvert {path}{name}.ipynb --to html --output {path}{name}')
os.system(f'jupyter nbconvert {path}{name}.ipynb --to markdown --output {path}{name}')